package ui;


import client.SendMessage;


class Authenticate {

	private String username = null;
	private String password = null;
	private boolean valid = false;
	
	public Authenticate() {
		this(null,null);
	}
	
	public Authenticate(String username, String password) {
		this.username = username;
		this.password = password;
		this.valid = false;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public boolean sendRequestToValidate() {
		return (SendMessage.validateLogin(username, password)) ? true : false;
	}
	
	public String getUsername() {
		return this.username;
	}
	
	public void setLogout() {
		this.valid = false;
	}
	
	public String toString() {
		return "Authenticate [username=" + username + ", password=" + password + ", valid=" + valid + "]";
	}

	public boolean isValidLogin() {
		return true;
		//return this.valid;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		result = prime * result + (valid ? 1231 : 1237);
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Authenticate other = (Authenticate) obj;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		if (valid != other.valid)
			return false;
		return true;
	}
}
